const path = require('path')
const fs = require('fs')
const bmp = require('bmp-js')

// 检查命令行参数是否正确
if (process.argv.length !== 3) {
  console.error('命令行参数格式错误。正确格式为：cmd file_name');
  process.exit(1);
}

//获取图片文件名
const fileName = process.argv[2];
console.log(fileName);

// 判断当前文件名是否为空
if (!path.basename(__filename)) {
  console.log('图片文件不存在！');
}

const width = 16
const height = 16
//创建空白位图缓冲区
const buffer = Buffer.allocUnsafe(width * height * 4)
//填充颜色
for (let i = 0; i < buffer.length; i += 4) {
  buffer[i] = 255  //red
  buffer[i + 1] = 0  //green
  buffer[i + 2] = 0  //blue
  buffer[i + 3] = 0  //alpho
}

//创建位图文件头和信息头
const data = bmp.encode({
  width: width,
  height: height,
  depth: 32,
  data: buffer
})
console.log(data);